package gui;

import javax.swing.JSlider;
import javax.swing.event.ChangeEvent;
import javax.swing.event.ChangeListener;

@SuppressWarnings("serial")
public class Sliders extends JSlider implements ChangeListener {
	public static final int PEOPLES_AT_BEGINN = 2;
	public static final int ZOMBIES_AT_BEGINN = 2;
	private JSlider numbOfPeoples = new JSlider(JSlider.HORIZONTAL, 0, 10, PEOPLES_AT_BEGINN);
	private JSlider numbOfZombies = new JSlider(JSlider.HORIZONTAL, 0, 10, ZOMBIES_AT_BEGINN);
	private JSlider speed = new JSlider(JSlider.HORIZONTAL, 0, 150, 60);

	public Sliders(DrawPerson p) {

		numbOfPeoples.addChangeListener(new ChangeListener() {

			@Override
			public void stateChanged(ChangeEvent e) {
				JSlider source = (JSlider) e.getSource();
				if (!source.getValueIsAdjusting()) {
					int n = source.getValue() - ListOfPerson.getPeoplesList().size();
					if (n >= 0) {
						ListOfPerson.addNpersons(n, ListOfPerson.getPeoplesList());
					} else {
						ListOfPerson.removeNpersons(Math.abs(n), ListOfPerson.getPeoplesList());

					}
				}

			}
		});
		numbOfPeoples.setMajorTickSpacing(5);
		numbOfPeoples.setMinorTickSpacing(1);
		numbOfPeoples.setPaintTicks(true);
		numbOfPeoples.setPaintLabels(true);
		numbOfPeoples.setSnapToTicks(true);
		numbOfPeoples.setToolTipText("Set number of PEOPLES");

		numbOfZombies.addChangeListener(new ChangeListener() {

			@Override
			public void stateChanged(ChangeEvent e) {
				JSlider source = (JSlider) e.getSource();
				if (!source.getValueIsAdjusting()) {
					int n = source.getValue() - ListOfPerson.getLiftOfZombies().size();
					if (n >= 0) {
						ListOfPerson.addNpersons(n, ListOfPerson.getLiftOfZombies());
					} else {
						ListOfPerson.removeNpersons(Math.abs(n), ListOfPerson.getLiftOfZombies());
					}
				}
			}
		});
		numbOfZombies.setMajorTickSpacing(5);
		numbOfZombies.setMinorTickSpacing(1);
		numbOfZombies.setPaintTicks(true);
		numbOfZombies.setPaintLabels(true);
		numbOfZombies.setSnapToTicks(true);
		numbOfZombies.setToolTipText("Set number of ZOMBIES");

		speed.addChangeListener(new ChangeListener() {

			@Override
			public void stateChanged(ChangeEvent e) {
				JSlider source = (JSlider) e.getSource();
				if (!source.getValueIsAdjusting()) {
					Main.getTimer().setDelay(150 - source.getValue());
				}

			}
		});
		speed.setMajorTickSpacing(30);
		speed.setMinorTickSpacing(10);
		speed.setPaintTicks(true);
		speed.setPaintLabels(true);
		speed.setSnapToTicks(true);
		speed.setToolTipText("Set speed");
	}

	public JSlider getNumbOfPeoples() {
		return numbOfPeoples;
	}

	public JSlider getNumbOfZombies() {
		return numbOfZombies;
	}

	public JSlider getSpeed() {
		return speed;
	}

	public void setSpeed(JSlider speed) {
		this.speed = speed;
	}

	@Override
	public void stateChanged(ChangeEvent e) {
		// TODO Auto-generated method stub

	}

}
